package com.example.ssmxuankeback.controller;

import com.example.ssmxuankeback.common.RestBean;
import com.example.ssmxuankeback.dto.ClassDTO;
import com.example.ssmxuankeback.dto.ClassPageQueryDTO;
import com.example.ssmxuankeback.service.ClassService;
import com.example.ssmxuankeback.vo.ClassVO;
import com.example.ssmxuankeback.vo.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Validated
@Tag(name = "ClassController", description = "班级管理接口")
@RequestMapping("/classes")
public class ClassController {

    @Autowired
    private ClassService classService;

    @Operation(summary = "获取班级详情")
    @GetMapping("/{classId}")
    public RestBean<ClassVO> getClassById(
            @Parameter(description = "班级ID", required = true)
            @PathVariable Long classId) {
        return classService.getClassByClassId(classId);
    }

    @Operation(summary = "创建班级")
    @PostMapping("/")
    public RestBean<ClassVO> createClass(
            @RequestBody @Validated ClassDTO dto) {
        return classService.addClass(dto);
    }

    @Operation(summary = "更新班级信息")
    @PutMapping("/{classId}")
    public RestBean<ClassVO> updateClass(
            @Parameter(description = "班级ID", required = true)
            @PathVariable Long classId,
            @RequestBody @Validated ClassDTO dto) {
        dto.setClassId(classId);
        return classService.updateClass(dto);
    }

    @Operation(summary = "删除班级")
    @DeleteMapping("/{classId}")
    public RestBean<ClassVO> deleteClass(
            @Parameter(description = "班级ID", required = true)
            @PathVariable Long classId) {
        return classService.deleteClassById(classId);
    }

    @Operation(summary = "分页查询班级")
    @GetMapping("/page")
    public RestBean<PageVO<ClassVO>> getClassPage(
            @Validated ClassPageQueryDTO queryDTO) {
        return classService.listByPage(queryDTO);
    }
}